package fileattrfilter

import (
	"strings"

	"gitee.com/guoliben/kydlp-doctotext/utils/ctrlledprint"
)

type FilepathFilterRuleObject struct {
	StartsWithList string
	EndsWithList   string
}

type FilepathFilterRule struct {
	Body FilepathFilterRuleObject
}

var filepathfilterrule = FilepathFilterRule{
	Body: FilepathFilterRuleObject{
		StartsWithList: "/proc;/sys;/dev;/run;/var/run/;/boot;/lost+found;/backup;/swap_file;/data/lost+found;/data/backup",
		EndsWithList:   ".tmp;.swp;.db;.db-journal;.lock;.info;.bin;.vdi;.msi;.msp",
	},
}

func FilterExcludeFilepath(path string) bool {
	ctrlledprint.Println("过滤例外文件路径...")

	startswiths := strings.Split(filepathfilterrule.Body.StartsWithList, ";")
	for i, _ := range startswiths {
		if strings.HasPrefix(path, startswiths[i]) {
			ctrlledprint.Println("文件路径前缀:", startswiths[i], "触发文件路径例外规则，将对其进行放行处理，不做内容检测！")
			return true
		}
	}
	endswiths := strings.Split(filepathfilterrule.Body.EndsWithList, ";")
	for i, _ := range endswiths {
		if strings.HasSuffix(path, endswiths[i]) {
			ctrlledprint.Println("文件路径后缀:", endswiths[i], "触发文件路径例外规则，将对其进行放行处理，不做内容检测！")
			return true
		}
	}

	return false
}
